package club.mzywucai.blog.file_system.controller;

import club.mzywucai.blog.file_system.pojo.domain.JsonData;
import club.mzywucai.blog.file_system.service.DownloadAndStarCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author mzywucai
 * @Description 记录点赞数和下载数的controller
 *      下载数统计和点赞次数统计同样是一个用户算一次。
 * @date 2019/2/12
 */
@RestController
public class DownloadAndStarCountController {
    @Autowired
    DownloadAndStarCountService downloadAndStarCountService;

    /**
     * @Description 
     * @author mzywucai
     * @time 2019-02-12
     * @see 
     * @return   club.mzywucai.blog.file_system.pojo.domain.JsonData
     * @params  [fileInfoId, session]
     */
    @GetMapping("/api/countStar/{fileInfoId}")
    public JsonData countStar(@PathVariable("fileInfoId") Long fileInfoId, HttpSession session) {
        if (null == fileInfoId) {
            fileInfoId = 0L;
        }

        JsonData json = downloadAndStarCountService.countStar(fileInfoId, session);

        return json;
    }

    @GetMapping("/api/countDownload/{fileInfoId}")
    public JsonData countDownload(@PathVariable Long fileInfoId, HttpSession session) {
        if (null == fileInfoId) {
            fileInfoId = 0L;
        }

        JsonData json = downloadAndStarCountService.countDownload(fileInfoId, session);

        return json;
    }
}
